namespace RivercrabNet
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    public class IndicatorMomentumIndex : BaseIndicator
    {
        private LineShape tlsMtm;
        private LineShape tlsMtmMa;

        public IndicatorMomentumIndex()
        {
            base.IndType = IndicatorType.MTM;
            base.IndName = "MTM";
            base.IndDesc = "动量指标";
            base.IndPeriod.Add(new IndicatorPeriod(0, "N", 12.0));
            base.IndPeriod.Add(new IndicatorPeriod(1, "N1", 6.0));
            base.SourceDic["Close"] = "";
            base.fields = new string[] { "MTM", "MTMMA" };
        }

        public override bool Contains(object obj)
        {
            if ((obj != this.tlsMtm) && (obj != this.tlsMtmMa))
            {
                return false;
            }
            return true;
        }

        public override double[] Get(int r)
        {
            double num = Convert.ToDouble(base.Crab.DataSource.Rows[r][base.SourceDic["Close"]]);
            double num2 = 0.0;
            if ((r - base.IndPeriod[0].ParamValue) >= 0.0)
            {
                num2 = Convert.ToDouble(base.Crab.DataSource.Rows[r - ((int) base.IndPeriod[0].ParamValue)][base.SourceDic["Close"]]);
            }
            double curValue = num - num2;
            double num4 = Common.CalcuteMovingAvg(r, (int) base.IndPeriod[1].ParamValue, this.tlsMtmMa.Name, this.tlsMtm.Name, curValue, base.Crab.DataSource);
            return new double[] { curValue, num4 };
        }

        public override List<BaseShape> GetShapeList()
        {
            return new List<BaseShape> { this.tlsMtm, this.tlsMtmMa };
        }

        public override void Remove()
        {
            base.Crab.DeleteShape(this.TlsMtm);
            base.Crab.DeleteShape(this.TlsMtmMa);
        }

        public override bool Set(int r, string target)
        {
            try
            {
                DataRow row = base.Crab.DataSource.Rows[r];
                foreach (string str in base.SourceDic.Values)
                {
                    if ((str == target) || (target == null))
                    {
                        foreach (string str2 in base.SourceDic.Values)
                        {
                            if (row[str2] is DBNull)
                            {
                                return false;
                            }
                        }
                        double[] numArray = this.Get(r);
                        base.Crab.SetValue(this.TlsMtm.Name, numArray[0], r);
                        base.Crab.SetValue(this.TlsMtmMa.Name, numArray[1], r);
                        return true;
                    }
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        public override void SetParam(string[] fields, string[] source, double[] periods, int panelID)
        {
            base.IndPeriod[0].ParamValue = periods[0];
            base.IndPeriod[1].ParamValue = periods[1];
            this.TlsMtm = base.Crab.AddLine(fields[0], panelID);
            base.Crab.SetLine(fields[0], fields[0], Color.White, 1, 0.01, 2, DashStyle.Solid);
            this.TlsMtmMa = base.Crab.AddLine(fields[1], panelID);
        }

        public LineShape TlsMtm
        {
            get
            {
                return this.tlsMtm;
            }
            set
            {
                this.tlsMtm = value;
            }
        }

        public LineShape TlsMtmMa
        {
            get
            {
                return this.tlsMtmMa;
            }
            set
            {
                this.tlsMtmMa = value;
            }
        }
    }
}

